package com.ruoyi.project.cwsk.packge.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.cwsk.packge.domain.Package;
import com.ruoyi.project.cwsk.packge.service.IPackageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 渠道包管理Controller
 * 
 * @author songzc
 * @date 2020-01-09
 */
@Controller
@RequestMapping("/cwsk/package")
public class PackageController extends BaseController
{
    private String prefix = "cwsk/package";

    @Autowired
    private IPackageService packageService;

    @RequiresPermissions("cwsk:package:view")
    @GetMapping()
    public String packge()
    {
        return prefix + "/package";
    }

    /**
     * 查询渠道包管理列表
     */
    @RequiresPermissions("cwsk:package:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Package packge)
    {
        start2Page();
        List<Package> list = packageService.selectPackageList(packge);
        return getDataTable(list);
    }

    /**
     * 导出渠道包管理列表
     */
    @RequiresPermissions("cwsk:package:export")
    @Log(title = "渠道包管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Package packge)
    {
        List<Package> list = packageService.selectPackageList(packge);
        ExcelUtil<Package> util = new ExcelUtil<Package>(Package.class);
        return util.exportExcel(list, "package");
    }

    /**
     * 新增渠道包管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存渠道包管理
     */
    @RequiresPermissions("cwsk:package:add")
    @Log(title = "渠道包管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Package packge)
    {
        return toAjax(packageService.insertPackage(packge));
    }

    /**
     * 修改渠道包管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        Package packge = packageService.selectPackageById(id);
        mmap.put("package", packge);
        return prefix + "/edit";
    }

    /**
     * 修改保存渠道包管理
     */
    @RequiresPermissions("cwsk:package:edit")
    @Log(title = "渠道包管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Package packge)
    {
        return toAjax(packageService.updatePackage(packge));
    }

    /**
     * 删除渠道包管理
     */
    @RequiresPermissions("cwsk:package:remove")
    @Log(title = "渠道包管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(packageService.deletePackageByIds(ids));
    }
}
